package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.wingroom.WingRoomMessageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/3/19 22:47
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_REQ_MESSAGE_DETAIL, desc = "跨服来请求留言详情")
public class CrossGetMessageDetailCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.GetMessageCrossReqMsg crossReqMsg = WingRoomProto.GetMessageCrossReqMsg.parseFrom(packet.getBytes());
        long guestServerId = crossReqMsg.getGuestServerId();
        long guestUserId = crossReqMsg.getGuestUserId();
        long messageId = crossReqMsg.getMessageId();
        WingRoomProto.GetMessageDetailRespMsg.Builder respMsg
                = WingRoomMessageMgr.getMessageDetailInfo(packet.getPlayerId(), messageId, guestServerId, guestUserId);
        if (respMsg != null) {
            WingRoomProto.GetMessageRespCrossMsg.Builder respCrossMsg = WingRoomProto.GetMessageRespCrossMsg.newBuilder();
            respCrossMsg.setRespMsg(respMsg);
            respCrossMsg.setGuestServerId(guestServerId);
            respCrossMsg.setGuestUserId(guestUserId);
            YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_WING_ROOM_GET_MESSAGE_DETAIL_RESP, respCrossMsg);
            GamePlayerMgr.sendPacket(0, message);
        }
    }
}
